//
//  UIButton-Extension.swift
//  WBSwift
//
//  Created by maker on 2016/11/9.
//  Copyright © 2016年 maker. All rights reserved.
//

import UIKit

extension UIButton{
    
//    class func creatBtn(image:String,backImage:String) ->UIButton{
//        //1.创建 btn
//        let btn = UIButton()
//        btn.setImage(UIImage(named: image), forState: .Normal)
//        btn.setImage(UIImage(named: image + "_highlighted"), forState: .Highlighted)
//        btn.setBackgroundImage(UIImage(named: backImage), forState: .Normal)
//        btn.setBackgroundImage(UIImage(named: backImage + "_highlighted"), forState: .Highlighted)
//        btn.sizeToFit()
//        return btn
//    }
    
    ///swift 对系统的方法进行扩充推荐使用构造函数(便利构造器)
    /* [使用场景]:对系统提供的控件,方法创建更方便.扩充构造方法
     1.添加 convenience
     2.内部调用下 self.init()
     */
    convenience init(image:String,backImage:String) {
        self.init()
        setImage(UIImage(named: image), for: UIControlState())
        setImage(UIImage(named: image + "_highlighted"), for: .highlighted)
        setBackgroundImage(UIImage(named: backImage), for: UIControlState())
        setBackgroundImage(UIImage(named: backImage + "_highlighted"), for: .highlighted)
        sizeToFit()
    }
    
    convenience init(font:CGFloat,bgColor:UIColor,title:String) {
        self.init()
        setTitle(title, for: UIControlState())
        backgroundColor = bgColor
        titleLabel?.font = UIFont.systemFont(ofSize: font)
        
    }
}













